/************************************************************************/
/* Name : Kiwon Yun
/* Partner's name : Eric Rooney
/* File Name : Player.cpp
/* The name of assignment : Iteration 2
/************************************************************************/

#include "Player.h"
#include "Dealer.h"

Player::Player( Dealer* a_pDealer )
{
	m_pDealer = a_pDealer;
	m_pHand = new Hand();
	m_strPlayerName = NULL;
	m_nMoney = 0;
	m_bFold=false;
	m_bAllIn=false;
	m_bAllInAmount=0;
	m_bBetSoFar=0;
}

Player::~Player(void)
{
	if( m_pHand )
	{
		delete m_pHand;
		m_pHand = NULL;
	}

	if( m_strPlayerName )
	{
		delete m_strPlayerName;
		m_strPlayerName = NULL;
	}
}

Hand* Player::GetHand()
{
	return m_pHand;
}

void Player::SetPlayerName( const char* a_strPlayerName )
{
	m_strPlayerName = new char[ strlen( a_strPlayerName ) + 1 ];
	strcpy( m_strPlayerName, a_strPlayerName );
}

char* Player::GetPlayerName()
{
	return m_strPlayerName;
}

void Player::ShowHand()
{
	GetHand()->ShowHand();
}

int Player::Discard(int m_nCard1,int m_nCard2,int m_nCard3)
{	
	bool m_bDlt1=0, m_bDlt2=0, m_bDlt3=0, m_bDlt4=0, m_bDlt5=0;
	int m_nNumberDeleted=0; //keep track of # of deleted cards

	//check to see which cards to delete and only delete a card once
	if(m_nCard1 == 1 || m_nCard2 == 1 || m_nCard3 == 1)
	{
		m_bDlt1=1;
		m_nNumberDeleted++;  //count deleted card
	}
	if(m_nCard1 == 2 || m_nCard2 == 2 || m_nCard3 == 2)
	{
		m_bDlt2=1;
		m_nNumberDeleted++;  //count deleted card
	}
	if(m_nCard1 == 3 || m_nCard2 == 3 || m_nCard3 == 3)
	{
		m_bDlt3=1;
		m_nNumberDeleted++;  //count deleted card
	}
	if(m_nCard1 == 4 || m_nCard2 == 4 || m_nCard3 == 4)
	{
		m_bDlt4=1;
		m_nNumberDeleted++;  //count deleted card
	}
	if(m_nCard1 == 5 || m_nCard2 == 5 || m_nCard3 == 5)
	{
		m_bDlt5=1;
		m_nNumberDeleted++;  //count deleted card
	}
	m_pHand->DeleteCard( m_bDlt1, m_bDlt2, m_bDlt3, m_bDlt4, m_bDlt5);
	
	m_pHand->ReorderCards( m_bDlt1, m_bDlt2, m_bDlt3, m_bDlt4, m_bDlt5);
	
	return m_nNumberDeleted;

}


void Player::ReorderCards(int m_nCard1,int m_nCard2,int m_nCard3)
{	
	bool m_bDlt1=0, m_bDlt2=0, m_bDlt3=0, m_bDlt4=0, m_bDlt5=0;
	int m_nNumberDeleted=0; //keep track of # of deleted cards

	//check to see which cards to delete and only delete a card once
	if(m_nCard1 == 1 || m_nCard2 == 1 || m_nCard3 == 1)
	{
		m_bDlt1=1;
	}
	if(m_nCard1 == 2 || m_nCard2 == 2 || m_nCard3 == 2)
	{
		m_bDlt2=1;
	}
	if(m_nCard1 == 3 || m_nCard2 == 3 || m_nCard3 == 3)
	{
		m_bDlt3=1;
	}
	if(m_nCard1 == 4 || m_nCard2 == 4 || m_nCard3 == 4)
	{
		m_bDlt4=1;
	}
	if(m_nCard1 == 5 || m_nCard2 == 5 || m_nCard3 == 5)
	{
		m_bDlt5=1;
	}
		
	m_pHand->FinalReorderCards( m_bDlt1, m_bDlt2, m_bDlt3, m_bDlt4, m_bDlt5);

}

void Player::RequestCard()
{
	m_pDealer->RequestCard( this );
}

void Player::SetMoney( int a_nMoney )
{
	m_nMoney = a_nMoney;
}

int Player::GetMoney()
{
	return m_nMoney;
}

void Player::SetFold(bool a_bFold)
{
	m_bFold=a_bFold;
}

bool Player::GetFold()
{
	return m_bFold;
}

void Player::SetAllIn(bool a_bAllIn)
{
	m_bAllIn=a_bAllIn;
}

bool Player::GetAllIn()
{
	return m_bAllIn;
}

void Player::SetAllInAmount(int a_bAllInAmount)
{
	m_bAllInAmount=a_bAllInAmount;
}

int Player::GetAllInAmount()
{
	return m_bAllInAmount;
}

void Player::SetBetSoFar(int a_bBetSoFar)
{
	m_bBetSoFar=a_bBetSoFar;
}

int Player::GetBetSoFar()
{
	return m_bBetSoFar;
}
